Skip to content

[Stacked PR 5/5] Add GDN backward pass 8k and 64k latency and memory benchmark suite - #5098

Draft
Rohan-Bierneni wants to merge 1 commit into
rbierneni-gdn-4-model-integrationfrom
rbierneni-gdnv3-bwd
Draft

[Stacked PR 5/5] Add GDN backward pass 8k and 64k latency and memory benchmark suite#5098
Rohan-Bierneni wants to merge 1 commit into
rbierneni-gdn-4-model-integrationfrom
rbierneni-gdnv3-bwd

Conversation

@Rohan-Bierneni

@Rohan-Bierneni Rohan-Bierneni commented Sep 2, 2026

Copy link
Copy Markdown
Collaborator

Stacked PR Chain

Stack Status Branch Base PR
PR 1 🔗 Stack PR 1 rbierneni-gdn-1-ci-hygiene main #5151 - [Stacked PR 1/5] Fix upstream pyink formatting and GMM v2 compatibility for Qwen3.5
PR 2 🔗 Stack PR 2 rbierneni-gdn-2-fwd-kernel rbierneni-gdn-1-ci-hygiene #5152 - [Stacked PR 2/5] Import local Tokamax GDN forward kernel with custom remat for backward pass support
PR 3 🔗 Stack PR 3 rbierneni-gdn-3-bwd-kernel rbierneni-gdn-2-fwd-kernel #5153 - [Stacked PR 3/5] Add decoupled GDN Pallas backward pass kernel and parity tests
PR 4 🔗 Base PR rbierneni-gdn-4-model-integration rbierneni-gdn-3-bwd-kernel #5154 - [Stacked PR 4/5] Enable GDN backward pass kernel and hybrid precision in Qwen3 model
PR 5 🚀 This PR (#5098) rbierneni-gdnv3-bwd rbierneni-gdn-4-model-integration #5098 - [Stacked PR 5/5] Add GDN backward pass 8k and 64k latency and memory benchmark suite

Description

This is PR 5 of 5 (the capstone PR #5098) in the stacked series enabling the Pallas Gated Delta Net (GDN) backward pass kernel in MaxText.

This PR adds the comprehensive Cloud TPU latency and memory benchmark suite comparing the Decoupled GDN Pallas backward pass kernel against Pure JAX remat:

  1. Benchmark Suite (tests/unit/gdn_benchmark_test.py):
    • Measures forward latency, backward latency, end-to-end step time, and peak memory usage across sequence lengths from 2k up to 64k (8k and 64k Ghostfish profiles).
    • Validates memory scaling under long contexts, demonstrating the HBM and VMEM advantages of the decoupled Pallas backward pass with $T^{-1}$ matrix reuse.
    • Provides profiling and compilation timing analysis on Cloud TPU v4/v5/v6e.

Files Changed

  • tests/unit/gdn_benchmark_test.py: Standalone 8k and 64k Cloud TPU latency and memory benchmark suite.

Tests

  • Verified with pre-commit run --files ... (all hooks passed).
  • Benchmark executable via python3 tests/unit/gdn_benchmark_test.py on Cloud TPU.

Checklist

  • I have performed a self-review of my code.
  • I have necessary comments in my code, particularly in hard-to-understand areas.
  • I have run end-to-end tests and verified pre-commit linters pass.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a fused analytical Pallas Gated Delta Net (GDN) kernel and backward pipeline, integrating it into the Qwen3 model. Key changes include the addition of the hybrid_bwd_analytical_pipeline and a suite of supporting local GDN kernel files to handle causal Conv1D and Gated Delta Rule operations with cached triangular inverse matrices. Additionally, sublane tiling logic is adjusted in the GMM and TGMM kernels. Feedback on the changes highlights a numerical inconsistency where an epsilon of 1e-12 is used for L2 normalization in the backward pass instead of the 1e-6 used in the forward pass, as well as an opportunity to simplify the sublane alignment assignment in the TGMM kernel.


if use_qk_norm_in_gdn:
d_q_scaled = d_q_proj * scale
r_q = jnp.sqrt(jnp.sum(q_orig**2, axis=-1, keepdims=True) + 1e-12)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The epsilon value 1e-12 used here for calculating the norm of q is inconsistent with the value 1e-6 used in the forward pass (l2norm at line 521). For numerical stability and correctness of the gradient, the same epsilon value should be used in both forward and backward computations.

Suggested change
r_q = jnp.sqrt(jnp.sum(q_orig**2, axis=-1, keepdims=True) + 1e-12)
r_q = jnp.sqrt(jnp.sum(q_orig**2, axis=-1, keepdims=True) + 1e-6)

- q_unit * jnp.sum(d_q_scaled * q_unit, axis=-1, keepdims=True)
) / r_q

r_k = jnp.sqrt(jnp.sum(k_orig**2, axis=-1, keepdims=True) + 1e-12)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Similar to the calculation for r_q, the epsilon value 1e-12 used here for r_k is inconsistent with the 1e-6 used in the forward pass. This should be corrected to 1e-6 to ensure numerical consistency.

Suggested change
r_k = jnp.sqrt(jnp.sum(k_orig**2, axis=-1, keepdims=True) + 1e-12)
r_k = jnp.sqrt(jnp.sum(k_orig**2, axis=-1, keepdims=True) + 1e-6)

Comment on lines +224 to +226
common_sublane = min(size_lhs_sublane, size_rhs_sublane)
size_lhs_sublane = common_sublane
size_rhs_sublane = common_sublane

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The logic to ensure size_lhs_sublane and size_rhs_sublane are equal can be simplified into a single line, improving readability.

Suggested change
common_sublane = min(size_lhs_sublane, size_rhs_sublane)
size_lhs_sublane = common_sublane
size_rhs_sublane = common_sublane
size_lhs_sublane = size_rhs_sublane = min(size_lhs_sublane, size_rhs_sublane)

@Rohan-Bierneni
Rohan-Bierneni force-pushed the rbierneni-gdnv3-bwd branch 3 times, most recently from 83ce15c to 5a5586c Compare September 6, 2026 03:33
@Rohan-Bierneni Rohan-Bierneni changed the title Test Fused GDN Backward Pass Kernel w/ MaxText Test GDN Backward Pass Kernel w/ MaxText Sep 6, 2026
@codecov

codecov Bot commented Sep 6, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@Rohan-Bierneni Rohan-Bierneni changed the title Test GDN Backward Pass Kernel w/ MaxText [Stacked PR 5/5] Add GDN 8k and 64k latency and memory benchmark suite Sep 6, 2026
@Rohan-Bierneni
Rohan-Bierneni changed the base branch from main to rbierneni-gdn-4-model-integration September 6, 2026 04:30
@Rohan-Bierneni Rohan-Bierneni changed the title [Stacked PR 5/5] Add GDN 8k and 64k latency and memory benchmark suite [Stacked PR 5/5] Add GDN backward pass 8k and 64k latency and memory benchmark suite Sep 6, 2026
…benchmark suite

- Add standalone 8k and 64k Ghostfish Cloud TPU latency and memory benchmark suite (gdn_benchmark_test.py).
- Provide comparative benchmarking between Pure JAX remat and Decoupled GDN Pallas backward pass kernel across sequence lengths up to 64k.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant